package com.wangrui.client.grid;

import gwtupload.client.MultiUploader;

import java.util.List;
import java.util.ListResourceBundle;

import com.smartgwt.client.widgets.events.ClickEvent;  
import com.smartgwt.client.widgets.events.ClickHandler; 
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.RecordList;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.wangrui.client.GreetingService;
import com.wangrui.client.GreetingServiceAsync;
import com.wangrui.client.data.BeanSipfLogDTO;
import com.wangrui.client.record.SipfLogRecordd;

public class SipfLogGrid extends ListGrid {
	
	
	public SipfLogRecordd sipfLogRecord;
	
	 protected  String getCellCSSText(ListGridRecord record, int rowNum, int colNum) {   
          if (getFieldName(colNum).equals("STATUS")) {   
              if (sipfLogRecord.getSTATUS().equals("不正常")) {   
                  return "font-weight:bold; color:#d64949;";   
              } else if (sipfLogRecord.getSTATUS().equals("正常")) {   
                  return "font-weight:bold; color:#287fd6;";   
              } else {   
                  return super.getCellCSSText(record, rowNum, colNum);   
              }   
          } else {   
              return super.getCellCSSText(record, rowNum, colNum);   
          }   
      } 
	 
	 
	 //添加编辑图标及监听事件
	 protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {   
		  
         String fieldName = this.getFieldName(colNum);   

         if (fieldName.equals("editField")) {   
             HLayout recordCanvas = new HLayout(3);   
             recordCanvas.setHeight(22);   
             recordCanvas.setAlign(Alignment.CENTER);   
             ImgButton editImg = new ImgButton();   
             editImg.setShowDown(false);   
             editImg.setShowRollOver(false);   
             editImg.setLayoutAlign(Alignment.CENTER);   
             editImg.setSrc("silk/comment_edit.png");   
             editImg.setPrompt("编辑");   
             editImg.setHeight(16);   
             editImg.setWidth(16);   
 
             
             editImg.addClickHandler(new ClickHandler() {
				
			
				public void onClick(ClickEvent event) {
					// TODO Auto-generated method stub
					SC.say("这是："+record.getAttribute("OC_DATE"));
		
				}
			});

             recordCanvas.addMember(editImg);   

             return recordCanvas;   
         } 
//            else if (fieldName.equals("buttonField")) {   
//             IButton button = new IButton();   
//             button.setHeight(18);   
//             button.setWidth(65);                       
//             button.setIcon("flags/16/" + record.getAttribute("countryCode") + ".png");   
//             button.setTitle("Info");   
////             button.addClickHandler(new ClickHandler() {   
////                 public void onClick(ClickEvent event) {   
////                     SC.say(record.getAttribute("countryName") + " info button clicked.");   
////                 }   
////             });   
//             return button;   
//         } else {   
             return null;   
//         }   

     }   

	public SipfLogGrid() {
		
		

		setWidth100();
		setHeight100();
		setShowAllRecords(true);
		setShowRecordComponents(true);           
		setShowRecordComponentsByCell(true); 
		setCanRemoveRecords(true); 
//		setAlign(Alignment.CENTER);
//		setAutoFitAllText(getTitleField());
//		setGroupByField("STATUS"); 
//		setGroupStartOpen(GroupStartOpen.ALL);
		
	
		ListGridField ocdateField = new ListGridField("OC_DATE", "日期", 80);
		ListGridField StatusField = new ListGridField("STATUS", "总体情况");
		ListGridField personField = new ListGridField("PERSON", "记录人");
		ListGridField editField = new ListGridField("editField", "编辑"); 
		
		editField.setAlign(Alignment.LEFT);
		           
       
		setFields(ocdateField, personField, StatusField,editField);

		setCanResizeFields(true);

		//获得日志基本信息的RPC
		GreetingServiceAsync getSipfLogService = GreetingService.Util.getInstance();

		AsyncCallback cb_getSipfLog = new AsyncCallback() {


			public void onFailure(Throwable caught) {}

			@Override
			public void onSuccess(Object result) {
				
				List data = (List)result;
				
				BeanSipfLogDTO[] array = new BeanSipfLogDTO[data.size()];
				
				RecordList sipfLogList = new RecordList();
				
				for(int i=0;i<data.size();i++){
					
					array[i]=(BeanSipfLogDTO)data.get(i);
					
					sipfLogRecord= new SipfLogRecordd(array[i].OC_DATE,array[i].STATUS,array[i].PERSON);
					
					System.out.println(array[i].OC_DATE+"!!!!!!!!!!!!!");
					
					sipfLogList.add(sipfLogRecord);
					
					
					System.out.println("打印日志返回的数据："+array[i].PERSON);
					
				
				}
				setData(sipfLogList);

			}

		};  getSipfLogService.getSipfLog(cb_getSipfLog);
		
		
	
	
		}

}
